//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
//---------------------------------------------------------------------------
#include "vLHistorique.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "CComboBx"
#pragma link "CEdit"
#pragma resource "*.dfm"
//---------------------------------------------------------------------------
//          Constructeur
//---------------------------------------------------------------------------
__fastcall THisto::THisto(TComponent* Owner)
    : TForm(Owner)
{
    try {
        cbUser          = new CComboBox(this);       //Composant 0
        cbOperation     = new CComboBox(this);       //Composant 1
        cbLogiciel      = new CComboBox(this);       //Composant 2
        cbVersion       = new CComboBox(this);       //Composant 3

        cbRef           = new CComboBox(this);       //Composant 4
        cbDesignation   = new CComboBox(this);       //Composant 5

        MesCombos = NULL;
        MesCombos = new TList();

        m_nColumnToSort = 0;
        m_nLastColumn   = 0;
        m_bAscToDesc    = true;

        TDateTime dtDate =  TDateTime::CurrentDateTime();
        DateDebut->Date  =  (AnsiString)"01/01/"+dtDate.FormatString("yyyy");
        DateFin->Date    =  dtDate.FormatString("dd/mm/yyyy");

        ConstruireComposant();
        RemplirFiltre();

        m_bAfficher = true;
        ConstruireListView();
        Afficher(Filtrer());

    }catch( Exception &e ) {
        EIC_DISPLAY_EXCEPTION(e);}
}
//---------------------------------------------------------------------------
//          Destructeur
//---------------------------------------------------------------------------
__fastcall THisto::~THisto()
{
    try {
        for(int i=0; i<MesCombos->Count; i++)
            delete (CComboBox*)MesCombos->Items[i];
    }catch( Exception &e ) {
        EIC_DISPLAY_EXCEPTION(e);}
}
//---------------------------------------------------------------------------
//          Construire les CComboBox
//---------------------------------------------------------------------------
void __fastcall THisto::ConstruireComposant()
{
    try {
        //cbUser
        cbUser->Parent  = pFilter;
        cbUser->Name    = "User";
        cbUser->ItemIndex = -1;
        cbUser->Left    = 88;
        cbUser->Top     = 34;
        cbUser->Width   = 200;
        cbUser->Height  = 21;
        cbUser->Style   = csDropDownList;

        //cbOperation
        cbOperation->Parent  = pFilter;
        cbOperation->Name    = "Operation";
        cbOperation->ItemIndex = -1;
        cbOperation->Left    = 88;
        cbOperation->Top     = 66;
        cbOperation->Width   = 200;
        cbOperation->Height  = 21;
        cbOperation->Style   = csDropDownList;

        //cbLogiciel
        cbLogiciel->Parent  = pFilter;
        cbLogiciel->Name    = "Logiciel";
        cbLogiciel->ItemIndex = -1;
        cbLogiciel->Left    = 88;
        cbLogiciel->Top     = 98;
        cbLogiciel->Width   = 200;
        cbLogiciel->Height  = 21;
        cbLogiciel->Style   = csDropDownList;

        //cbVersion Remplie en fonction du logiciel désirez.
        cbVersion->Parent  = pFilter;
        cbVersion->Name    = "Version";
        cbVersion->Enabled = false;
        cbVersion->Clear();
        cbVersion->ItemIndex = -1;
        cbVersion->Left    = 147;
        cbVersion->Top     = 130;
        cbVersion->Width   = 140;
        cbVersion->Height  = 21;
        cbVersion->Style   = csDropDownList;

        //cbReference
        cbRef->Parent  = pFilter;
        cbRef->Name    = "Ref";
        cbRef->ItemIndex = -1;
        cbRef->Left    = 408;
        cbRef->Top     = 42;
        cbRef->Width   = 400;
        cbRef->Height  = 21;

        //cbDesignation
        cbDesignation->Parent  = pFilter;
        cbDesignation->Name    = "Designation";
        cbDesignation->ItemIndex = -1;
        cbDesignation->Left    = 408;
        cbDesignation->Top     = 82;
        cbDesignation->Width   = 400;
        cbDesignation->Height  = 21;

        MesCombos->Add((void*)cbUser);          //0
        MesCombos->Add((void*)cbOperation);     //1
        MesCombos->Add((void*)cbLogiciel);      //2
        MesCombos->Add((void*)cbVersion);       //3
        MesCombos->Add((void*)cbRef);           //4
        MesCombos->Add((void*)cbDesignation);   //5

    }catch( Exception &e ) {
        EIC_DISPLAY_EXCEPTION(e);}
}
//---------------------------------------------------------------------------
//          Définition des requetes afin de remplir les comboBoxFiltre
//---------------------------------------------------------------------------
AnsiString __fastcall THisto::DefinirRequeteFiltre( const AnsiString &asCombo )
{
    AnsiString asFiltreRequete = "";
    try {
        if(asCombo == COMBO_USER)
            asFiltreRequete = "Select distinct histo_nom from historique order by histo_nom";
        else if(asCombo == COMBO_OPE)
            asFiltreRequete = "Select distinct histo_operation from historique order by histo_operation";
        else if(asCombo == COMBO_LOG)
            asFiltreRequete = "Select distinct histo_log from historique order by histo_log";
        else if(asCombo == COMBO_REF)
            asFiltreRequete = "select distinct histo_ref from historique order by histo_ref";
        else if(asCombo == COMBO_DES)
            asFiltreRequete = "Select distinct histo_ref_sous_nom from historique order by histo_ref_sous_nom";
    }catch( Exception &e ) {
        EIC_DISPLAY_EXCEPTION(e);
        asFiltreRequete = "";}
    return asFiltreRequete;
}
//---------------------------------------------------------------------------
//      Remplir les filtres SAUF pour Version (en fonction de logiciel)
//---------------------------------------------------------------------------
void __fastcall THisto::RemplirFiltre()
{
    TdmWebHelp * dmWebHelp = NULL;
    TZZMySqlQuery * MaRequete = NULL;
    try {
        dmWebHelp = new TdmWebHelp( (TComponent*)0 );
        MaRequete = new TZZMySqlQuery( (TComponent*)0 );
        MaRequete->Database = dmWebHelp->dbWebHelp;

        CComboBox * pCombo;
        for(int i=0; i<MesCombos->Count; i++) {
            pCombo = (CComboBox*)MesCombos->Items[i];
            if(pCombo) {
                if( pCombo->Name != COMBO_VER ) {
                    pCombo->Clear();
                    if(     (pCombo->Name == COMBO_REF)
                        ||  (pCombo->Name == COMBO_DES) ) {
                        pCombo->Items->Add(MSG_SAISIR);
                        pCombo->OnExit   = OnExitCComboBox;
                    }else {
                        pCombo->OnChange = OnChangeCComboBox;
                    }

                    MaRequete->Sql->Text = DefinirRequeteFiltre(pCombo->Name);
                    MaRequete->Open();
                    MaRequete->First();

                    while(!MaRequete->Eof) {
                        if(!asRequete(0).IsEmpty())
                            pCombo->Items->Add(asRequete(0));
                        MaRequete->Next();
                    }

                    if( pCombo->Items->Count == 0) {
                        pCombo->Items->Clear();
                        pCombo->Items->Add(MSG_NODATA);
                        pCombo->ItemIndex = 0;
                        pCombo->Enabled = false;
                    }

                    MaRequete->Sql->Clear();
                }
            }
        }

        MaRequete->Close();
    }catch( Exception &e ) {
        EIC_DISPLAY_EXCEPTION(e);}
    if(MaRequete) {delete MaRequete; MaRequete = NULL;}
    if(dmWebHelp) {delete dmWebHelp; dmWebHelp = NULL;}
}
//---------------------------------------------------------------------------
//          Remplir la combo version
//---------------------------------------------------------------------------
void __fastcall THisto::RemplirComboVer( void )
{
    TdmWebHelp * dmWebHelp = NULL;
    TZZMySqlQuery * MaRequete = NULL;
    try {
        dmWebHelp = new TdmWebHelp( (TComponent*)0 );
        MaRequete = new TZZMySqlQuery( (TComponent*)0 );
        MaRequete->Database = dmWebHelp->dbWebHelp;

        CComboBox * pCombo;
        for(int i=0; i<MesCombos->Count; i++) {
            pCombo = (CComboBox*)MesCombos->Items[i];
            if(pCombo) {
                if( pCombo->Name == COMBO_VER ) {
                    pCombo->Clear();

                    MaRequete->Sql->Text = (AnsiString) "select distinct histo_ver "+
                                                        "from historique "+
                                                        "where histo_log = "+QuotedStr(cbLogiciel->Items->Strings[cbLogiciel->ItemIndex]);
                    MaRequete->Open();
                    MaRequete->First();

                    while(!MaRequete->Eof) {
                        if(!asRequete(0).IsEmpty())
                            pCombo->Items->Add(asRequete(0));
                        MaRequete->Next();
                    }

                    if( pCombo->Items->Count == 0) {
                        pCombo->Items->Clear();
                        pCombo->Enabled = false;
                    }
                    pCombo->OnChange = OnChangeCComboBox;
                    MaRequete->Sql->Clear();
                }
            }
        }

        MaRequete->Close();
    }catch( Exception &e ) {
        EIC_DISPLAY_EXCEPTION(e);}
    if(MaRequete) {delete MaRequete; MaRequete = NULL;}
    if(dmWebHelp) {delete dmWebHelp; dmWebHelp = NULL;}
}
//---------------------------------------------------------------------------
//          Afficher
//---------------------------------------------------------------------------
void __fastcall THisto::Afficher( const AnsiString &asFiltre )
{
    TdmWebHelp * dmWebHelp = NULL;
    TZZMySqlQuery * MaRequete = NULL;
    try {
        lvHistorique->Items->Clear();
        if(m_bAfficher) {
            dmWebHelp = new TdmWebHelp( (TComponent*)0 );

            MaRequete = new TZZMySqlQuery( (TComponent*)0 );
            MaRequete->Database = dmWebHelp->dbWebHelp;

            MaRequete->Sql->Text = (AnsiString)"select  histo_nom,"+           //0
                                                       "histo_operation,"+     //1
                                                       "histo_date,"+          //2
                                                       "histo_time,"+          //3
                                                       "histo_log,"+           //4
                                                       "histo_ver,"+           //5
                                                       "histo_ref,"+           //6
                                                       "histo_ref_sous_nom,"+  //7
                                                       "histo_pageweb "+       //8
                                               "from historique "+ asFiltre;

            MaRequete->Open();
            MaRequete->First();
            int i =0;
            while(!MaRequete->Eof) {
                lvHistorique->Items->Add();
                lvHistorique->Items->Item[i]->SubItems->Add(asRequete(0));
                lvHistorique->Items->Item[i]->SubItems->Add(asRequete(1));
                lvHistorique->Items->Item[i]->SubItems->Add(asRequete(2));
                lvHistorique->Items->Item[i]->SubItems->Add(asRequete(3));
                lvHistorique->Items->Item[i]->SubItems->Add(asRequete(4));
                lvHistorique->Items->Item[i]->SubItems->Add(asRequete(5));
                lvHistorique->Items->Item[i]->SubItems->Add(asRequete(6));
                lvHistorique->Items->Item[i]->SubItems->Add(asRequete(7));
                lvHistorique->Items->Item[i]->SubItems->Add(asRequete(8));
                i++;
                MaRequete->Next();
            }
            MaRequete->Sql->Clear();
            MaRequete->Close();
        }

    }catch( Exception &e ) {
        EIC_DISPLAY_EXCEPTION(e);}
    if(MaRequete) {delete MaRequete; MaRequete = NULL;}
    if(dmWebHelp) {delete dmWebHelp; dmWebHelp = NULL;}
}
//---------------------------------------------------------------------------
//      Dessine moi une listview
//---------------------------------------------------------------------------
void __fastcall THisto::lvHistoriqueDrawItem(
      TCustomListView *Sender, TListItem *Item, TRect &Rect,
      TOwnerDrawState State)
{
    try {
        if(m_bAfficher) {
            TRect Rectangle(0,0,0,0);
            int nLongeurCol   = 0;
            int nLongeurColX2 = 0;
            long X = 0;
            long Y = Rect.Top;

            for(int i=0; i<Item->SubItems->Count; i++) {
                if(i != 0 ) {
                    nLongeurCol = Sender->Column[i]->Width;
                    X += nLongeurCol;
                }
                nLongeurColX2    = Sender->Column[i+1]->Width;

                Rectangle.Left   = X;
                Rectangle.Right  = (X+nLongeurColX2);
                Rectangle.Top    = Y;
                Rectangle.Bottom = Rect.Bottom;

                if(!Item->SubItems->Strings[i].IsEmpty()) {
                    Sender->Canvas->Brush->Color = clWindow;
                    Sender->Canvas->TextRect(Rectangle,X+4,Y ,Item->SubItems->Strings[i]);
                }else {
                    Sender->Canvas->Brush->Color = clInactiveBorder;
                    Sender->Canvas->FillRect(Rectangle);
                }
            }
        }
    }catch( Exception &e ) {
        EIC_DISPLAY_EXCEPTION(e);}
}
//---------------------------------------------------------------------------
//      Construire la listview
//---------------------------------------------------------------------------
void __fastcall THisto::ConstruireListView( void )
{
    try {
        int Longueur = lvHistorique->Width;

        TListColumn  *NewColumn;
        lvHistorique->Columns->Clear();

        NewColumn = lvHistorique->Columns->Add();
        NewColumn->Caption = "";
        NewColumn->Width = 0;

        NewColumn = lvHistorique->Columns->Add();
        NewColumn->Caption  = "Nom";
        NewColumn->ImageIndex = 0;
        NewColumn->Width = Longueur * 0.07;

        NewColumn = lvHistorique->Columns->Add();
        NewColumn->Caption  = "Opération";
        NewColumn->Alignment = taCenter;
        NewColumn->Width = Longueur * 0.15;

        NewColumn = lvHistorique->Columns->Add();
        NewColumn->Caption  = "Date";
        NewColumn->Alignment = taCenter;
        NewColumn->Width = Longueur * 0.06;

        NewColumn = lvHistorique->Columns->Add();
        NewColumn->Caption  = "Heure";
        NewColumn->Alignment = taCenter;
        NewColumn->Width = Longueur * 0.05;

        NewColumn = lvHistorique->Columns->Add();
        NewColumn->Caption  = "Logiciel";
        NewColumn->Alignment = taCenter;
        NewColumn->Width = Longueur * 0.10;

        NewColumn = lvHistorique->Columns->Add();
        NewColumn->Caption  = "Version";
        NewColumn->Alignment = taCenter;
        NewColumn->Width = Longueur * 0.05;

        NewColumn = lvHistorique->Columns->Add();
        NewColumn->Caption  = "Référence";
        NewColumn->Alignment = taCenter;
        NewColumn->Width = Longueur * 0.15;

        NewColumn = lvHistorique->Columns->Add();
        NewColumn->Caption  = "Désignation";
        NewColumn->Alignment = taCenter;
        NewColumn->Width = Longueur * 0.15;

        NewColumn = lvHistorique->Columns->Add();
        NewColumn->Caption  = "Page Web";
        NewColumn->Alignment = taCenter;
        NewColumn->Width = Longueur * 0.205;
        NewColumn->AutoSize = true;

    }catch( Exception &e ) {
        EIC_DISPLAY_EXCEPTION(e);}
}
//---------------------------------------------------------------------------
//          Remise à zéro des filtres
//---------------------------------------------------------------------------
void __fastcall THisto::sbRazClick(TObject *Sender)
{
    try {

        TDateTime dtDate  =  TDateTime::CurrentDateTime();
        DateDebut->Date   =  (AnsiString)"01/01/"+dtDate.FormatString("yyyy");
        DateFin->Date     =  dtDate.FormatString("dd/mm/yyyy");

        CComboBox * pCombo;
        for(int i=0; i<MesCombos->Count; i++) {
            pCombo = (CComboBox*)MesCombos->Items[i];
            pCombo->ItemIndex = AUCUNE_SELECTION;
            pCombo->Clear();
        }
        cWeb->Text = EmptyStr;
        cbVersion->Enabled = false;
        
        m_bAfficher = true;
        Afficher(Filtrer());

        RemplirFiltre();
    }catch( Exception &e ) {
    EIC_DISPLAY_EXCEPTION(e);}
}
//---------------------------------------------------------------------------
//           Remplir structure filtre
//---------------------------------------------------------------------------
void __fastcall THisto::RemplirStructure( Filtrage * stFiltre )
{
    try {
        CComboBox * pCombo;
        for(int i=0; i<MesCombos->Count; i++) {
            pCombo = (CComboBox*)MesCombos->Items[i];

            if(pCombo->Name == COMBO_USER) {
                if(pCombo->ItemIndex != AUCUNE_SELECTION)
                    strcpy(stFiltre->Condition_Nom, pCombo->Items->Strings[pCombo->ItemIndex].c_str());
            }else if(pCombo->Name == COMBO_OPE) {
                if(pCombo->ItemIndex != AUCUNE_SELECTION)
                    strcpy(stFiltre->Condition_Ope, pCombo->Items->Strings[pCombo->ItemIndex].c_str());
            }else if(pCombo->Name == COMBO_LOG) {
                if(pCombo->ItemIndex != AUCUNE_SELECTION)
                    strcpy(stFiltre->Condition_Log, pCombo->Items->Strings[pCombo->ItemIndex].c_str());
            }else if(pCombo->Name == COMBO_VER) {
                if(pCombo->ItemIndex != AUCUNE_SELECTION)
                    strcpy(stFiltre->Condition_Ver, pCombo->Items->Strings[pCombo->ItemIndex].c_str());
            }else if(pCombo->Name == COMBO_REF) {
                if( pCombo->Text != MSG_SAISIR) {
                    if(pCombo->ItemIndex != 0 && pCombo->ItemIndex != AUCUNE_SELECTION)
                        strcpy(stFiltre->Condition_Ref, pCombo->Items->Strings[pCombo->ItemIndex].c_str());
                    else
                        strcpy(stFiltre->Condition_Ref, pCombo->Text.c_str());
                }
            }else if(pCombo->Name == COMBO_DES) {
                if( pCombo->Text != MSG_SAISIR) {
                    if(pCombo->ItemIndex != 0 && pCombo->ItemIndex != AUCUNE_SELECTION)
                        strcpy(stFiltre->Condition_Des, pCombo->Items->Strings[pCombo->ItemIndex].c_str());
                    else
                        strcpy(stFiltre->Condition_Des, pCombo->Text.c_str());
                }
            }
        }

        if( !cWeb->Text.IsEmpty() )
            strcpy( stFiltre->Condition_Web, cWeb->Text.c_str() );
        
    }catch( Exception &e ) {
    EIC_DISPLAY_EXCEPTION(e);}
}
//---------------------------------------------------------------------------
//      Filtrer
//---------------------------------------------------------------------------
AnsiString __fastcall THisto::Filtrer()
{
    AnsiString asFiltre = "where ";

    try {
        memset(&m_stFiltre, 0, sizeof(m_stFiltre));
        RemplirStructure(&m_stFiltre);

        CComboBox * pCombo;
        for(int i=0; i<MesCombos->Count; i++) {
            pCombo = (CComboBox*)MesCombos->Items[i];
            if(pCombo->Name == COMBO_USER) {
                if(!AnsiString(m_stFiltre.Condition_Nom).IsEmpty()) {
                    if( asFiltre == "where ")
                        asFiltre += "histo_nom=\""+(AnsiString)m_stFiltre.Condition_Nom+"\" ";
                    else
                        asFiltre += "and histo_nom=\""+AnsiString(m_stFiltre.Condition_Nom)+"\" ";
                }
            }else if(pCombo->Name == COMBO_OPE) {
                if(!AnsiString(m_stFiltre.Condition_Ope).IsEmpty()) {
                    if( asFiltre == "where ")
                        asFiltre += "histo_operation=\""+AnsiString(m_stFiltre.Condition_Ope)+"\" ";
                    else
                        asFiltre += "and histo_operation=\""+AnsiString(m_stFiltre.Condition_Ope)+"\" ";
                }
            }else if(pCombo->Name == COMBO_LOG) {
                if(!AnsiString(m_stFiltre.Condition_Log).IsEmpty()) {
                    if( asFiltre == "where ")
                        asFiltre += "histo_log=\""+AnsiString(m_stFiltre.Condition_Log)+"\" ";
                    else
                        asFiltre += "and histo_log=\""+AnsiString(m_stFiltre.Condition_Log)+"\" ";
                }
            }else if(pCombo->Name == COMBO_VER) {
                if(!AnsiString(m_stFiltre.Condition_Ver).IsEmpty()) {
                    if( asFiltre == "where ")
                        asFiltre += "histo_ver=\""+AnsiString(m_stFiltre.Condition_Ver)+"\" ";
                    else
                        asFiltre += "and histo_ver=\""+AnsiString(m_stFiltre.Condition_Ver)+"\" ";
                }
            }else if(pCombo->Name == COMBO_REF) {
                if(!AnsiString(m_stFiltre.Condition_Ref).IsEmpty()) {
                    if( asFiltre == "where ")
                        asFiltre += "histo_ref=\""+AnsiString(m_stFiltre.Condition_Ref)+"\" ";
                    else
                        asFiltre += "and histo_ref=\""+AnsiString(m_stFiltre.Condition_Ref)+"\" ";
                }
            }else if(pCombo->Name == COMBO_DES) {
                if(!AnsiString(m_stFiltre.Condition_Des).IsEmpty()) {
                    if( asFiltre == "where ")
                        asFiltre += "histo_ref_sous_nom=\""+AnsiString(m_stFiltre.Condition_Des)+"\" ";
                    else
                        asFiltre += "and histo_ref_sous_nom=\""+AnsiString(m_stFiltre.Condition_Des)+"\" ";
                }
            }
        }

        if(!AnsiString(m_stFiltre.Condition_Web).IsEmpty()) {
            if( asFiltre == "where ")
                asFiltre += "histo_pageweb like \"%"+AnsiString(m_stFiltre.Condition_Web)+"%\" ";
            else
                asFiltre += "and histo_pageweb like \"%"+AnsiString(m_stFiltre.Condition_Web)+"%\" ";
        }

        //Date
        if( asFiltre == "where ")
            asFiltre += "histo_date between "+QuotedStr(DateDebut->Date.FormatString("yyyy-mm-dd"))+" and "+QuotedStr(DateFin->Date.FormatString("yyyy-mm-dd"));
        else
            asFiltre += "and histo_date between "+QuotedStr(DateDebut->Date.FormatString("yyyy-mm-dd"))+" and "+QuotedStr(DateFin->Date.FormatString("yyyy-mm-dd"));
    }catch( Exception &e ) {
    EIC_DISPLAY_EXCEPTION(e);
    asFiltre = "";}

    return asFiltre;
}
//---------------------------------------------------------------------------
//      Evenement OnChange
//---------------------------------------------------------------------------
void __fastcall THisto::OnChangeCComboBox(TObject *Sender)
{
    try {
        CComboBox * MyCombo = dynamic_cast<CComboBox*>(Sender);
        if( MyCombo ) {
            if( MyCombo->Name == COMBO_LOG ) {
                cbVersion->Enabled = true;
                RemplirComboVer();
            }
            Afficher(Filtrer());
        }
    }catch( Exception &e ) {
    EIC_DISPLAY_EXCEPTION(e);}
}
//---------------------------------------------------------------------------
//      Evenement OnExit
//---------------------------------------------------------------------------
void __fastcall THisto::OnExitCComboBox(TObject *Sender)
{
    try {
        CComboBox * MyCombo = dynamic_cast<CComboBox*>(Sender);
        if( MyCombo )
            Afficher(Filtrer());
    }catch( Exception &e ) {
    EIC_DISPLAY_EXCEPTION(e);}
}
//---------------------------------------------------------------------------
//      Evenement Ondatedebut
//---------------------------------------------------------------------------
void __fastcall THisto::DateDebutCloseUp(TObject *Sender)
{
    try {
        Afficher(Filtrer());
    }catch( Exception &e ) {
    EIC_DISPLAY_EXCEPTION(e);}
}
//---------------------------------------------------------------------------
//      Evenement Ondatefin
//---------------------------------------------------------------------------
void __fastcall THisto::DateFinCloseUp(TObject *Sender)
{
    try {
        Afficher(Filtrer());
    }catch( Exception &e ) {
    EIC_DISPLAY_EXCEPTION(e);}
}
//---------------------------------------------------------------------------
//                  Tri par ordre alphabétique
//---------------------------------------------------------------------------
void __fastcall THisto::lvHistoriqueColumnClick(TObject *Sender,
      TListColumn *Column)
{
    try {
        m_nColumnToSort = Column->Index;
        if (m_nColumnToSort != m_nLastColumn) m_bAscToDesc = true;
        else                                  m_bAscToDesc = !m_bAscToDesc;
        ((TCustomListView *)Sender)->AlphaSort();
        m_nLastColumn = m_nColumnToSort;

        // On efface les flèches
        for( int i=0;i<(( TListView*)Sender)->Columns->Count;i++) {
            (( TListView*)Sender)->Columns->Items[i]->ImageIndex = -1;
        }
        // On affiche une flèche indiquant le tri en cours
        Column->ImageIndex = (m_bAscToDesc)?enumArrow_ASC:enumArrow_DESC;

    } catch (Exception &e) {
        EIC_DISPLAY_EXCEPTION( e);}
}
//---------------------------------------------------------------------------
//                      Compare 2 item
//---------------------------------------------------------------------------
void __fastcall THisto::lvHistoriqueCompare(TObject *Sender,
      TListItem *Item1, TListItem *Item2, int Data, int &Compare)
{
    try {
        if (m_nColumnToSort == 0) {
            Compare = CompareText(Item1->Caption, Item2->Caption );
            if (!m_bAscToDesc) Compare = -Compare;
        } else {
            int ix = m_nColumnToSort - 1;
            Compare = CompareText( Item1->SubItems->Strings[ix], Item2->SubItems->Strings[ix] );
            if (!m_bAscToDesc) Compare = -Compare;
        }
    } catch (Exception &e) {
        EIC_DISPLAY_EXCEPTION( e);}
}
//---------------------------------------------------------------------------
void __fastcall THisto::cWebExit(TObject *Sender)
{
    try {
        Afficher(Filtrer());
    } catch (Exception &e) {
        EIC_DISPLAY_EXCEPTION( e);}
}
//---------------------------------------------------------------------------

